package com.huang.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huang.entity.OperationLog;
import com.huang.mapper.OperationLogMapper;
import com.huang.model.PageResult;
import com.huang.model.request.LogQuery;
import com.huang.model.response.OperationLogResp;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志服务
 *
 * @author Ikaros
 * @since 2025/9/6 18:53 星期六
 */
@Service
public class OperationLogService extends ServiceImpl<OperationLogMapper, OperationLog> {

    /**
     * 分页查询操作日志列表
     *
     * @param logQuery 日志查询条件
     * @return 分页结果
     */
    public PageResult<OperationLogResp> listOperationLogVO(LogQuery logQuery) {
        // 查询操作日志数量
        List<OperationLogResp> operationLogRespList = baseMapper.selectOperationLogVOList(logQuery);
        if (operationLogRespList.isEmpty()) {
            return new PageResult<>();
        }
        return new PageResult<>(operationLogRespList, operationLogRespList.getFirst().getTotalCount());
    }

    /**
     * 保存操作日志
     *
     * @param operationLog 操作日志
     */
    public void saveOperationLog(OperationLog operationLog) {
        // 保存操作日志
        baseMapper.insert(operationLog);
    }
}
